<%@ page import="com.mapper.OManagementMapper" %>
<%@ page import="com.Imp.OManagementMapperImpl" %>
<%@ page import="com.entity.OManagement" %>
<%@ page import="java.util.List" %>
<%@ page import="com.mapper.StoreMapper" %>
<%@ page import="com.Imp.StoreMapperImpl" %>
<%@ page import="com.mapper.CustomerMapper" %>
<%@ page import="com.Imp.CustomerMapperImpl" %>
<%@ page import="com.entity.Store" %>
<%@ page import="com.entity.Customer" %>
<%@ page import="com.mapper.OrderMapper" %>
<%@ page import="com.Imp.OrderMapperImpl" %>
<%@ page import="com.entity.Order" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>页面布局</title>
    <!-- 新 Bootstrap5 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css">

    <!--  popper.min.js 用于弹窗、提示、下拉菜单 -->
    <script src="https://cdn.staticfile.org/popper.js/2.9.3/umd/popper.min.js"></script>

    <!-- 最新的 Bootstrap5 核心 JavaScript 文件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>

<div class="container-fluid">
    <div class="row">
        <div class="col-md-12 header" style="background-color: black">
            <h1>外卖员</h1>
        </div>
    </div>

    <div class="row">
        <div class="col-md-2 sidebar">
            <div class="sidebar-menu">
                <ul>
                    <li><a href="main_deliveryman.jsp"><img src="img/main.png" height="18" width="18">&nbsp首页</a></li>
                    <li class="active"><a href="orderInformation.jsp" style="background-color: #55aaff"><img src="img/waimai.png" height="18" width="18">&nbsp配送单管理</a></li>
                    <li><a href="information_deliveryman.jsp"><img src="img/personal.png" height="18" width="18">&nbsp个人信息</a></li>
                </ul>
            </div>
        </div>
        <div class="col-md-10 main-content">
            <div v-for="store in stores" :key="store.id" class="store-info">
                <div class="container mt-3">
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>订单编号</th>
                            <th>商家</th>
                            <th>下单时间</th>
                            <th>下单手机号</th>
                            <th>配送状态</th>
                            <th>地址</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <%
                            String userName = (String) session.getAttribute("username");
                            OManagementMapper oManagementMapper = new OManagementMapperImpl();
                            StoreMapper storeMapper = new StoreMapperImpl();
                            CustomerMapper customerMapper = new CustomerMapperImpl();
                            OrderMapper orderMapper = new OrderMapperImpl();
                            List<OManagement> oManagementList = oManagementMapper.getOrdersBydeliveryId(userName);
                            for (OManagement oManagement : oManagementList) {
                                  Store store = storeMapper.getStoreBystoreId(oManagement.getStoreId());
                                  Customer customer = customerMapper.getCustomerByUserName(oManagement.getCustomerId());
                        %>
                        <tr>
                            <td><%=oManagement.getOrderId()%></td>
                            <td><%=store.getName()%></td>
                            <td><%=oManagement.getOrderTime()%></td>
                            <td><%=customer.getPhone()%></td>
                            <td><%=customer.getAddress()%></td>
                            <td><%=oManagement.getOrderState()%></td>
                            <%
                                if(oManagement.getOrderState().equals("配送中")){
                            %>
                            <td>
                                <form action="OrderManagementController?op=changeState" method="post">
                                    <input type="hidden" name="orderId" value="<%=oManagement.getOrderId()%>">
                                    <button type="submit" class="btn btn-secondary">送达</button>
                                </form>
                            </td>
                            <%
                                }
                                else{
                            %>
                            <td>
                                <p> 已送达</p>
                            </td>
                            <%
                                }
                            %>
                        </tr>
                        <%
                            }
                        %>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
